﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using DBBase;
using System.Windows.Forms;

namespace Business
{
    public partial class anjianJCZPZ : Form
    {
        public anjianJCZPZ()
        {
            InitializeComponent();
        }
        private float X;

        private float Y;

        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
                if (con.Controls.Count > 0)
                    setTag(con);
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            foreach (Control con in cons.Controls)
            {

                string[] mytag = con.Tag.ToString().Split(new char[] { ':' });
                float a = Convert.ToSingle(mytag[0]) * newx;
                con.Width = (int)a;
                a = Convert.ToSingle(mytag[1]) * newy;
                con.Height = (int)(a);
                a = Convert.ToSingle(mytag[2]) * newx;
                con.Left = (int)(a);
                a = Convert.ToSingle(mytag[3]) * newy;
                con.Top = (int)(a);
                Single currentSize = Convert.ToSingle(mytag[4]) * Math.Min(newx, newy);
                if (currentSize <= 0)
                {
                    currentSize = 0.1f;
                }
                con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                if (con.Controls.Count > 0)
                {
                    setControls(newx, newy, con);
                }
            }

        }

        void Form1_Resize(object sender, EventArgs e)
        {
            float newx = (this.Width) / X;
            float newy = this.Height / Y;
            setControls(newx, newy, this);
            this.Text = this.Width.ToString() + " " + this.Height.ToString();

        }
        private void anjianJCZPZ_Load(object sender, EventArgs e)
        {

            this.Resize += new EventHandler(Form1_Resize); this.Resize += new EventHandler(Form1_Resize);

            X = this.Width;
            Y = this.Height;


            setTag(this);
            Form1_Resize(new object(), new EventArgs());//x,y可在实例化时赋值,最后这句是新加的，在MDI时有用

            inicbx(com_lwcj, "table_lwcj");
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from StationInfor");
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                txtdh.Text = dt.Rows[0]["SI_NO"].ToString().Trim();
                txtjczmc.Text = dt.Rows[0]["SI_NAME"].ToString().Trim();
                txtzgxkzh.Text = dt.Rows[0]["SI_FAMEWORK"].ToString().Trim();
                txtphone.Text = dt.Rows[0]["SI_OPHNOE"].ToString().Trim();
                txtaddr.Text = dt.Rows[0]["SI_ADDR"].ToString().Trim();
                text_web.Text = dt.Rows[0]["SI_WEB"].ToString().Trim();
                text_jczbh.Text = dt.Rows[0]["SI_JCZBH"].ToString().Trim();
                text_lshkt.Text = dt.Rows[0]["SI_LSHKT"].ToString().Trim();
                text_sqm.Text = dt.Rows[0]["SI_SQM"].ToString().Trim();

                text_hpcsh.Text = dt.Rows[0]["SI_HPCSZ"].ToString().Trim();
                text_zdsc.Text = dt.Rows[0]["SI_AJSC"].ToString().Trim();
                text_sqqzr.Text = dt.Rows[0]["SI_SQQZR"].ToString().Trim();
                text_lzsffj.Text = dt.Rows[0]["SI_LZSFFJ"].ToString().Trim();

                che_Networking.Checked = dt.Rows[0]["SI_Networking"].ToString().Trim().Contains("True") ? true : false;
                che_MotoNetworking.Checked = dt.Rows[0]["SI_MotoNetworking"].ToString().Trim().Contains("True") ? true : false; 
                if (dt.Rows[0]["SI_SQM"].ToString().Trim() == "1")
                {
                    che_SQB.Checked = true;
                }
                else
                {
                    che_SQB.Checked = false;
                }
                che_pda.Checked = dt.Rows[0]["SI_pdajy"].ToString().Trim().Contains("True") ? true : false;
                che_dpd.Checked = dt.Rows[0]["SI_DPD"].ToString().Trim().Contains("True") ? true : false;
                text_url.Text = dt.Rows[0]["webservice"].ToString().Trim();
                com_lwcj.Text = dt.Rows[0]["SI_LWCJ"].ToString().Trim();
                Standard.Text = dt.Rows[0]["Standard"].ToString().Trim();
                qichejcxlb.Text = dt.Rows[0]["SI_QicheJCXLB"].ToString().Trim();
                motojcxlb.Text = dt.Rows[0]["SI_MotoJCXLB"].ToString().Trim();
                che_sxb.Checked = dt.Rows[0]["SI_sxb"].ToString().Trim().Contains("True") ? true : false;
                text_ycyzl.Text = dt.Rows[0]["SI_ycyzl"].ToString().Trim();
                cbxWKCC.Text = dt.Rows[0]["SI_wkcc"].ToString().Trim();
                txtUrlWKCC.Text = dt.Rows[0]["SI_wkccUrl"].ToString().Trim();
                che_rgpd.Checked = dt.Rows[0]["SI_rgpd"].ToString().Trim().Contains("True") ? true : false;
                che_bhgdy.Checked = dt.Rows[0]["SI_bhgdy"].ToString().Trim().Contains("True") ? true : false;
                che_bptcsyz.Checked = dt.Rows[0]["SI_bptcsyz"].ToString().Trim().Contains("True") ? true : false;
                cb_same.Checked = dt.Rows[0]["SI_same"].ToString().Trim().Contains("True") ? true : false;
            }

           

        }

        private void OK_Click(object sender, EventArgs e)
        {
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from StationInfor");
            DataTable dt = mquery.GetTable(sql);
            string ssql = "";
            if (dt.Rows.Count > 0)
            {
                ssql = string.Format(@"update StationInfor set 
                                            SI_NO='{0}',
                                            SI_NAME='{1}',
                                            SI_FAMEWORK='{2}',
                                            SI_OPHNOE='{3}',
                                            SI_ADDR='{4}',
                                            SI_ZJED={5},
                                            SI_WEB='{6}',
                                            SI_JCZBH='{7}',
                                            SI_LSHKT='{8}',
                                            SI_SQM='{9}',
                                            SI_Networking={10},
                                            SI_SQB='{11}',
                                            SI_SQQZR='{12}',
                                            SI_HPCSZ='{13}',
                                            SI_AJSC='{14}',
                                            SI_LZSFFJ='{15}',
                                            webservice='{16}',
                                            SI_LWCJ='{17}',
                                            SI_MotoNetworking ={18},
                                            Standard='{19}',
                                            SI_DPD='{20}',
                                            SI_QicheJCXLB='{21}',
                                            SI_MotoJCXLB='{22}',
                                            SI_pdajy={23},
                                            SI_ycyzl='{24}',
                                            SI_sxb='{25}',
                                            SI_wkcc='{26}',
                                            SI_wkccUrl='{27}',
                                            SI_rgpd='{28}',
                                            SI_bhgdy='{29}',
                                            SI_bptcsyz='{30}',
                                            SI_same='{31}'",
                                            txtdh.Text,
                                            txtjczmc.Text,
                                            txtzgxkzh.Text,
                                            txtphone.Text,
                                            txtaddr.Text,
                                            0,
                                            text_web.Text,
                                            text_jczbh.Text,
                                            text_lshkt.Text,
                                            text_sqm.Text,
                                            che_Networking.Checked ? 1 : 0,
                                            che_SQB.Checked ? "1" : "0",
                                            text_sqqzr.Text,
                                            text_hpcsh.Text,
                                            text_zdsc.Text,
                                            text_lzsffj.Text,
                                            text_url.Text,
                                            com_lwcj.Text,
                                            che_MotoNetworking.Checked ? 1 : 0,
                                            Standard.Text,
                                            che_dpd.Checked ? 1 : 0,
                                            qichejcxlb.Text.Trim(),
                                            motojcxlb.Text.Trim(), 
                                            che_pda.Checked ? 1 : 0,
                                            text_ycyzl.Text.Trim(),
                                            che_sxb.Checked ? 1 : 0,
                                            cbxWKCC.Text,
                                            txtUrlWKCC.Text,
                                            che_rgpd.Checked ? 1 : 0,
                                            che_bhgdy.Checked? 1 : 0,
                                            che_bptcsyz.Checked? 1 : 0,
                                            cb_same.Checked? 1 : 0);
            }
            else
            {
                ssql = string.Format(@"insert into StationInfor (
                                    SI_NO,
                                    SI_NAME,
                                    SI_FAMEWORK,
                                    SI_OPHNOE,
                                    SI_ADDR,
                                    SI_ZJED,
                                    SI_WEB,
                                    SI_JCZBH,
                                    SI_LSHKT,
                                    SI_SQM,
                                    SI_Networking,
                                    SI_SQB,
                                    SI_SQQZR,
                                    SI_HPCSZ,
                                    SI_AJSC,
                                    SI_LZSFFJ,
                                    webservice,
                                    SI_LWCJ,
                                    SI_MotoNetworking,
                                    Standard,
                                    SI_DPD,
                                    SI_QicheJCXLB,
                                    SI_MotoJCXLB,
                                    SI_pdajy,
                                    SI_ycyzl,
                                    SI_sxb,
                                    SI_wkcc,
                                    SI_wkccUrl,
                                    SI_rgpd,
                                    SI_bhgdy,
                                    SI_bptcsyz,
                                    SI_same) values (
                                    '{0}',
                                    '{1}',
                                    '{2}',
                                    '{3}',
                                    '{4}',
                                     {5},
                                    '{6}',
                                    '{7}',
                                    '{8}',
                                    '{9}',
                                    {10},
                                    '{11}',
                                    '{12}',
                                    '{13}',
                                    '{14}',                                
                                    '{15}',
                                    '{16}',
                                    '{17}',
                                     {18},
                                    '{19}',
                                    '{20}',
                                    '{21}',
                                    '{22}',
                                     {23},
                                    '{24}',
                                    '{25}',
                                    '{26}',
                                    '{27}',
                                    '{28}',
                                    '{29}',
                                    '{30}',
                                    '{31}')",
                                    txtdh.Text,
                                    txtjczmc.Text,
                                    txtzgxkzh.Text,
                                    txtphone.Text,
                                    txtaddr.Text,
                                    0,
                                    text_web.Text,
                                    text_jczbh.Text,
                                    text_lshkt.Text,
                                    text_sqm.Text,
                                    che_Networking.Checked ? 1 : 0,
                                    che_SQB.Checked ? "1" : "0",
                                    text_sqqzr.Text,
                                    text_hpcsh.Text,
                                    text_zdsc.Text,
                                    text_lzsffj.Text,
                                    text_url.Text,
                                    com_lwcj.Text,
                                    che_MotoNetworking.Checked ? 1 : 0,
                                    Standard.Text,
                                    che_dpd.Checked ? 1 : 0,
                                    qichejcxlb.Text.Trim(),
                                    motojcxlb.Text.Trim(),
                                    che_pda.Checked ? 1 : 0,
                                    text_ycyzl.Text.Trim(),
                                    che_sxb.Checked ? 1 : 0,
                                    cbxWKCC.Text,
                                    txtUrlWKCC.Text,
                                    che_rgpd.Checked ? 1 : 0,
                                    che_bhgdy.Checked ? 1 : 0,
                                    che_bptcsyz.Checked ? 1 : 0,
                                    cb_same.Checked ? 1 : 0);
            }
            mquery.InsertDB(ssql);

            
        }
        void inicbx(ComboBox cbx, string dataname)
        {
            Query objquery = new Query();
            string ssqlex = "";
            ssqlex = string.Format(@"select * from {0} order by table_1", dataname);
            DataTable dt = objquery.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cbx.Items.Add(dt.Rows[i]["table_2"].ToString().Trim());
                if (i == 0)
                    cbx.Text = dt.Rows[0]["table_2"].ToString().Trim();
            }
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
        }

        private void anjianJCZPZ_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F6)
            {
                label22.Visible = true;
                text_ycyzl.Visible = true;
            }
        }

    
    }
}
